<?php

namespace Utils\SecurityBundle\CustomClass;

class SecurityFunctions {

  public static function clear($string, $trim = false, $int = false, $str = false) {
    $string = filter_var($string, FILTER_SANITIZE_STRING);
    $string = trim($string);
    $string = stripslashes($string);
    $string = strip_tags($string);
    $string = str_replace(array('‘', '’', '“', '”'), array("'", "'", '"', '"'), $string);

    if ($trim)
      $string = substr($string, 0, $trim);
    if ($int)
      $string = preg_replace("/[^0-9\s]/", "", $string);
    if ($str)
      $string = preg_replace("/[^a-zA-ZфцужэнгшүзкъйыбөахролдпячёсмитьвюещФЦУЖЭНГШҮЗКЪЙЫБӨАХРОЛДПЯЧЁСМИТЬВЮЕЩ0-9 _!-@#$%^&*()\s]/", "", $string);

    return $string;
  }
  
  public static function clearArray($array, $trim = false, $int = false, $str = false) {
      
    if(is_array($array)){
        $newArray = array();
        foreach($array AS $k => $string) {
            $string = filter_var($string, FILTER_SANITIZE_STRING);
            $string = trim($string);
            $string = stripslashes($string);
            $string = strip_tags($string);
            $string = str_replace(array('‘', '’', '“', '”'), array("'", "'", '"', '"'), $string);

            if ($trim)
              $string = substr($string, 0, $trim);
            if ($int)
              $string = preg_replace("/[^0-9\s]/", "", $string);
            if ($str)
              $string = preg_replace("/[^a-zA-ZфцужэнгшүзкъйыбөахролдпячёсмитьвюещФЦУЖЭНГШҮЗКЪЙЫБӨАХРОЛДПЯЧЁСМИТЬВЮЕЩ0-9 _!-@#$%^&*()\s]/", "", $string);

            $newArray[$k] = $string;
        }
        return $newArray;
    }else{
        return null;
    }
    
  }
}

?>
